package com.situ.b2c.product.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;

import com.situ.b2c.pojo.Product;
import com.situ.b2c.product.service.ProductService;
import com.situ.b2c.product.service.impl.ProductServiceImpl;


@WebServlet("/ProductSelectAllServlet")
public class ProductSelectAllServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ProductService productService;


	public ProductSelectAllServlet() {
		ApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
		productService = context.getBean(ProductService.class);
		
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		List<Product> prodList = productService.selectAllProduct();
		
		request.setAttribute("product", prodList);
		
		request.getRequestDispatcher("B2Choutai/product_show.jsp").forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
